package com.xiaomi.front.controller;

import com.xiaomi.front.service.commoditys.CommService;
import com.xiaomi.front.service.shopp_cart.ShoppCartService;
import com.xiaomi.pojo.Commoditys;
import com.xiaomi.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class HeadController {


    @Autowired
    private CommService commService;

    @Autowired
    private ShoppCartService shoppCartService;

    /*
    head.jsp 点击显示
    头部功能
    点击显示
     */
    @RequestMapping("/Front_Head")
    public String LoadHead(HttpSession session, Model model) {

        //点击显示商品推荐 根据商品类型id 跟字段模糊查询
        List<Commoditys> commoditys = commService.FindOne(1, "小米");
        model.addAttribute("commoditys", commoditys);

        List<Commoditys> commoditys2 = commService.FindOne(1, "Redmi");
        model.addAttribute("comlist2", commoditys2);

        List<Commoditys> commoditys3 = commService.FindOne(2, "电视");
        model.addAttribute("comlist3", commoditys3);

        List<Commoditys> commoditys4 = commService.FindOne(3, "");
        model.addAttribute("comlist4", commoditys4);

        List<Commoditys> commoditys5 = commService.FindOne(4, "");
        model.addAttribute("comlist5", commoditys5);

        List<Commoditys> commoditys6 = commService.FindOne(7, "路由器");
        model.addAttribute("comlist6", commoditys6);

        List<Commoditys> commoditys7 = commService.FindOne(8, "");
        model.addAttribute("comlist7", commoditys7);

        //头部显示购物车数量
        int count = 0;
        User loginUser = (User) session.getAttribute("user");
        if (loginUser != null) {
            count = shoppCartService.CartCount(loginUser.getUid());
        }
        model.addAttribute("count", count);

        return "front/head";
    }

    //tail.jsp显示
    @RequestMapping("/Front_Tail")
    public String LoadTail() {
        return "front/tail";
    }
}
